package com.peenongsaban.freelance.action;

import com.opensymphony.xwork2.ActionSupport;
import com.peenongsaban.freelance.bean.RegisterBean;
import com.peenongsaban.freelance.model.AuthorizeJobBean;
import com.peenongsaban.freelance.model.JobDetailModel;
import com.peenongsaban.freelance.service.JobDetailService;
import com.peenongsaban.freelance.utils.ConstantUtils;
import com.peenongsaban.freelance.utils.SessionUtils;

public class JobDetailAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private JobDetailModel model = new JobDetailModel();

	public String showJobDetail(){
		
		RegisterBean bean = (RegisterBean) SessionUtils.getSession(ConstantUtils.SESSION_LOGIN);
		if(bean==null){
			bean = new RegisterBean();
		}
		
		JobDetailService service = new JobDetailService();
		model.setJobDetail(service.getListJobDetail(model));
		model.setListCategoryJob(service.getListJobCategoryJob());
		model.setListLastJob(service.getListLastJob());
		model.setAptitudeTypeNameOfJob(service.getAptitudeTypeNameOfJobDetail(model));
		if(bean.getUser().getIdCard()!= null){
			model.setAuthorizeJob(service.chackAuthorizeJob(bean.getUser().getIdCard(), model.getJobDetail().getPostID()));
		}else{
			model.setAuthorizeJob(new AuthorizeJobBean());
		}
		model.setRequestJobRequestStatus(service.getUserRequestJob(model.getPostJobId(), ConstantUtils.STATUS_REQUEST_OF_REQUEST_JOB));
		model.setRequestJobApprovedStatus(service.getUserRequestJob(model.getPostJobId(), ConstantUtils.STATUS_APPROVED_OF_REQUEST_JOB));
		model.setRequestJobWorkingStatus(service.getUserRequestJob(model.getPostJobId(), ConstantUtils.STATUS_WORKING_OF_REQUEST_JOB));
		model.setRequestJobEstimateStatus(service.getUserRequestJob(model.getPostJobId(), ConstantUtils.STATUS_WAITING_ESTIMATE_OF_REQUEST_JOB));
		model.setRequestJobSuccessStatus(service.getUserRequestJob(model.getPostJobId(), ConstantUtils.STATUS_SUCCESS_OF_REQUEST_JOB));
		model.setRequestJobCancelStatus(service.getUserRequestJob(model.getPostJobId(), ConstantUtils.STATUS_CANCLE_OF_REQUEST_JOB));
		model.setRequestJobDetail(service.getRequestJobDeatil(bean.getUser().getIdCard(), model.getPostJobId()));
		model.setUrl("jobDetail?model.postJobId="+model.getPostJobId());
		
		return SUCCESS;
	}
	
	
	public JobDetailModel getModel() {
		return model;
	}

	public void setModel(JobDetailModel model) {
		this.model = model;
	}

}
